﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL.RF.ATETest;
using Model.RF.ATETest;

namespace DAL.RF.ATETest
{
    public class TwoDimensionSN : BaseRepository<TwoDimensionSNInfo>, ITwoDimensionSN
    {
        #region 静态变量定义
        private const string PARM_TDSN_PRODUCTSN = "@ProductSN";
        private const string PARM_TDSN_TDSN = "@TDSN";
        #endregion

        #region 数据检索部分
        public IList<TwoDimensionSNInfo> LoadEntities()
        {
            return null;
        }

        public TwoDimensionSNInfo LoadEntity<T1>(T1 productSN)
        {
            return null;
        }

        public string TwoDimensionSN_GetTDSNbySN(string productSN)
        {
            SqlParameter[] parm = GetSNParameter();
            parm[0].Value = productSN;
            parm[1].Direction = ParameterDirection.Output;
            parm[1].IsNullable = true;
            sqlHelper.ExecuteScalar(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "TwoDimensionSN_selectbyLastSN", parm);
            return parm[1].Value.ToString();
        }

        public IList<TwoDimensionSNInfo> TwoDimensionSN_GetbySN(string productSN)
        {
            SqlParameter parm = GetParameter();
            parm.Value = productSN;
            return ExcuteSqlToGetEntities("TwoDimensionSN_selectbySN", parm);
        }
        #endregion


        #region 参数部分
        public SqlParameter[] GetSNParameter()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TDSN_PRODUCTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_TDSN_TDSN, SqlDbType.NVarChar, 2000)                
                };
            return parms;  
        }
        #endregion


        #region 重写基类方法
        public override TwoDimensionSNInfo GetEntityRecord(SqlDataReader rdr)
        {
            TwoDimensionSNInfo entity = new TwoDimensionSNInfo()
            {
                ProductSN = rdr.GetValue(0).ToString(),
                TestTime = rdr.GetDateTime(1),
                ProductTypeID = rdr.GetValue(2).ToString(),
                UserID = rdr.GetValue(3).ToString(),
                ENAID = rdr.GetValue(4).ToString(),
                IsPass = rdr.GetValue(5).ToString(),
                IsSwitch = rdr.GetValue(6).ToString(),
                SpecVersion = rdr.GetValue(7).ToString(),
                TDSN = rdr.GetValue(8).ToString()
            };
            return entity;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter parm = new SqlParameter(PARM_TDSN_PRODUCTSN, SqlDbType.NVarChar, 50);
            return parm;
        }
        #endregion
    }
}
